package project_part2;

import static org.junit.Assert.*;

import org.junit.Test;

public class FindMatchTest2 {
	
	static final int DOB_BIT = 8;
	// static final int A_BIT = 8;
	static final int W_BIT = 4;
	static final int H_BIT = 2;
	static final int G_BIT = 1;
	
	int i,j;
	@Test
	public void testTemplate() {
		
		ContactList clist = new ContactList();
		Contact con = setContact(i);
		Contact res[] = null;
		MatchCriteria mc = setCriteria(i,false);
		
		clist.add(con);
		
		res = clist.findMatches(con, mc, j+1);
		assertEquals(1,res.length);
	}
	
	public Contact setContact(int num) {
		Contact c;

		String DOB = "10/10/2007";
		short weight = 200;
		int height = 5;
		Gender gender = Gender.FEMALE;

		if ((DOB_BIT & num) == 8)
			DOB = "10/10/2001";
		// if ((A_BIT & i) == 1)
		// age = 100;
		if ((W_BIT & num) == 4)
			weight = 100;
		if ((H_BIT & num) == 2)
			height = 6;
		if ((G_BIT & num) == 1)
			gender = Gender.MALE;

		c = new Contact("T", "T", "T", DOB);
		c.setWeight(weight);
		c.setHeight(height, height);
		c.setGender(gender);

		return c;
	}
	
	public Contact setMatch(int num) {
		Contact c;

		String DOB = "10/10/2007";
		short weight = 200;
		int height = 5;
		Gender gender = Gender.FEMALE;

		if ((DOB_BIT & num) == 8)
			DOB = "10/10/2001";
		// if ((A_BIT & i) == 1)
		// age = 100;
		if ((W_BIT & num) == 4)
			weight = 100;
		if ((H_BIT & num) == 2)
			height = 6;
		if ((G_BIT & num) == 1)
			gender = Gender.MALE;

		c = new Contact("F", "T", "T", DOB);
		c.setWeight(weight);
		c.setHeight(height, height);
		c.setGender(gender);

		return c;
	}


	public MatchCriteria setCriteria(int num, boolean inv) {
		MatchCriteria mc = new MatchCriteria();

		Gender gender = Gender.FEMALE;


			mc.ageHigh = 6;
			mc.ageLow = 4;
			mc.matchAge = inv;

			mc.weightHigh = 250;
			mc.weightLow = 150;
			mc.matchWeight = inv;

			mc.heightHigh = new ContactHeight(5, 8);
			mc.heightLow = new ContactHeight(5, 2);
			mc.matchHeight = inv;

			gender = Gender.FEMALE;
			mc.matchGender = inv;
	

		if ((DOB_BIT & num) == 8) {
			mc.ageHigh = 12;
			mc.ageLow = 10;
			mc.matchAge = true;
		}
		if ((W_BIT & num) == 4) {
			mc.weightHigh = 150;
			mc.weightLow = 50;
			mc.matchWeight = true;
		}
		if ((H_BIT & num) == 2) {
			mc.heightHigh = new ContactHeight(6, 9);
			mc.heightLow = new ContactHeight(6, 3);
			mc.matchHeight = true;
		}
		if ((G_BIT & num) == 1) {
			gender = Gender.MALE;
			mc.matchGender = true;
		}

		mc.addGender(gender);
		return mc;
	}
	
	public MatchCriteria setCriteriaInv(int num, boolean inv) {
		MatchCriteria mc = new MatchCriteria();

		Gender gender = Gender.FEMALE;


			mc.ageHigh = 12;
			mc.ageLow = 10;
			mc.matchAge = inv;

			mc.weightHigh = 150;
			mc.weightLow = 50;
			mc.matchWeight = inv;

			mc.heightHigh = new ContactHeight(6, 9);
			mc.heightLow = new ContactHeight(6, 3);
			mc.matchHeight = inv;

			gender = Gender.MALE;
			mc.matchGender = inv;
	

		if ((DOB_BIT & num) == 8) {
			mc.ageHigh = 7;
			mc.ageLow = 2;
			mc.matchAge = true;
		}
		if ((W_BIT & num) == 4) {
			mc.weightHigh = 250;
			mc.weightLow = 150;
			mc.matchWeight = true;
		}
		if ((H_BIT & num) == 2) {
			mc.heightHigh = new ContactHeight(5, 8);
			mc.heightLow = new ContactHeight(5, 2);
			mc.matchHeight = true;
		}
		if ((G_BIT & num) == 1) {
			gender = Gender.FEMALE;
			mc.matchGender = true;
		}

		mc.addGender(gender);
		return mc;
	}

	public int sumBits(int value) {
		int total = 0;

		if ((1 & value) == 1)
			total++;

		for (int i = 0; i < 31; i++) {
			value = value >> 1;

			if ((1 & value) == 1)
				total++;

		}

		return total;
	}

}
